#include "Reader.h"
#include <iostream>
#include <fstream>
#include <string>
#include <sstream>
#include <iterator>
#include <istream>
#include <vector>

using namespace std;

Reader::Reader(void)
{
}


Reader::~Reader(void)
{
}

DayAppCol* Reader::readFromFile(char* path)
{
	DayAppCol* model = new DayAppCol[5];
	string line;
	ifstream inputFile(path);
	if (inputFile.is_open())
	{
		while ( inputFile.good() )
		{
			getline (inputFile,line);
			stringstream ss(line);
			istream_iterator<string> itr(ss);
			istream_iterator<string> end;
			vector<string> results(itr,end);
			ostream_iterator<std::string> oit(std::cout);
			if(results.size()>0)
			{
				char* s = (char*)results[0].c_str();
				if(atoi(s)!=0) //entry data
				{
					if(results.size()==9) //correct entry size
					{
						string paData;
						for (int i=0;i<4;i++)
						{
							paData.append(results[i]);
							paData.append(" ");
						}						
						for(int i=0;i<5;i++)
						{
							int idx = i+4;
							string tmp(paData);
							char* dateStr = (char*)results[idx].c_str();
							if(strcmp(dateStr,"-")!=0)
							{
								//string entry = 
								tmp.append(dateStr);
								vector<string> *v= &model[i].dateEtCol;
								v->push_back(tmp);
							}
						}
					}
				}
			}
			results[0];
		}
		inputFile.close();
	}
	else cout << "Unable to open file"; 
	return model;
}